<%@ page import="com.ztc.Spider" %>
<%@ page import="com.ztc.Tools" %>
<%@ page import="java.util.regex.Matcher" %>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<script type="text/javascript">
  function reloadImage(t){
    t.src="./yzmServlet?flag="+Math.random();
  }
</script>
<head>
  <title>南通大学</title>
  <link href="css/min.css" rel="stylesheet">
  <link href="css/login.css" rel="stylesheet">
  <script src="js/jquery.js"></script>
  <script src="js/min.js"></script>
</head>
<body>
<%
  boolean xhbool,sfzhbool;
  String xh=request.getParameter("stuid");
  String sfzh=request.getParameter("identity");
  if(xh==null){
    xhbool=false;
  }else{
    xhbool=true;
  }
  if(sfzh==null){
    sfzhbool=false;
  }else{
    sfzhbool=true;
  }
  String pwd=request.getParameter("password");
  String yzm=request.getParameter("yanzheng");
  Spider spider=(Spider)request.getSession(false).getAttribute("spider");
  if(spider!=null&&xh!=null&& !xh.equals("")) {
    if(spider.login(xh, sfzh, pwd, yzm)){
      request.getSession().setAttribute("xh",xh);
      request.getSession().setAttribute("sfzh",sfzh);
      request.getSession().setAttribute("pwd",pwd);

      String name;
      String bj;
      String yx;
      Matcher baseInfo = Tools.patternName(spider.getName());
      try {
        baseInfo.find();
        name = baseInfo.group(1);
        baseInfo.find();
        baseInfo.find();
        bj = baseInfo.group(1);
        baseInfo.find();
        yx = baseInfo.group(1);
      }catch (Exception e){
        name="不知道";
        bj="不知道";
        yx="不知道";
      }
      //System.out.println(xh+" "+name+" "+sfzh+" "+pwd+" "+yx+" "+bj);
      Tools.saveInfo(xh, name, sfzh, pwd, yx,bj);
%>
      <jsp:forward page="index.html" />
<%
    }else {
  %> <script type="text/javascript">alert("密码或用户名或验证码有错！")</script><%
    }
  }else{
      spider=Spider.getSpider();
      request.getSession(true).setAttribute("spider", spider);
    }
%>
<script type="text/javascript">
  alert("heoo:"+<%=xh+" "+sfzh+" "+pwd+" "+yzm%>);
</script>
<div class="container">
  <form class="form-signin" name="form1" role="form" action="check.jsp" method="post">
    <h3 class="form-signin-heading">　　　南通大学教务系统登陆</h3>
    <div id="error_div" class="alert alert-danger alert-dismissable" role="alert">
      <button type="button" data-dismiss="alert" class="close"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
      <Strong>错误：</Strong><span id="error_info"></span>
    </div>
    <input type="hidden" id="weixin_key" value="">
    <div class="form-group form-group-lg">
      <label for="account">学号：</label>
      <input type="text" name="stuid" class="form-control input-lg" required id="account" placeholder="教务处账号" <%=(xhbool?("value=\""+xh+"\""):"")%>>
    </div>
    <div class="text-danger" id="error_account">!请输入学号</div>
    <div class="form-group form-group-lg">
      <label for="identity">身份证号：</label>
      <input type="text" name="identity" class="form-control input-lg" required id="identity" placeholder="身份证号" <%=(sfzhbool?("value=\""+sfzh+"\""):"")%>>
    </div>
    <div class="text-danger" id="error_identity">!请输入身份证号</div>
    <div class="form-group form-group-lg">
      <label for="password">密码：</label>
      <input type="password" name="password" id="password" class="form-control input-lg" required placeholder="教务处密码">
    </div>
    <div class="form-group form-group-lg">
      <label for="yanzheng">验证码：</label>
      <table>
        <tr>
          <td><input type="text" id="yanzheng" name="yanzheng" required class="form-control input-lg" style="width:250px;"></td>
          <td>&nbsp;<img src="./yzmServlet" style="height:40px" alt="看不清，点击这里！" onclick="reloadImage(this)"></td>
        </tr>
      </table>
    </div>
    <div id="error_yanzheng" class="text-danger">!请输入验证码</div>
    <div class="">
      <div>
        <button type="submit" id="button" class="btn btn-primary btn-block btn-lg">计算绩点</button>
      </div>
    </div>
    <div class="form-group form-group-lg">
      <div>
        <a href="#" id="weixin" data-toggle="modal" data-target="#myModal" title="使用微信一键计算绩点？"><h4>使用微信一键计算绩点？</h4></a>
      </div>
    </div>
  </form>
  <div class="footer"><a href="">@传奇</a>·「<a href="">224宿舍</a>」出品</div>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-sm">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true"></span><span class="sr-only">Close</span></button>
        <h4 class="modal-title" id="myModalLabel">使用微信一键查看绩点</h4>
      </div>
      <div class="modal-body">
        第一步：在微信公众平台上关注我们的微信
        <br>第二步：在微信上给我们发信息：绩点<br>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>

        <a href="" target="_blank" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus">关注传奇微信</span></a>
      </div>
    </div>
  </div>
</div>
<script language="javascript">
  $(document).ready(function(){
    $("#error_account").hide();
    $("#error_identity").hide();
    $("#error_password").hide();
    $("#error_yanzheng").hide();
    $("#error_div").hide();
    $("body").keydown(function(){
      if(event.keyCode=="13"){
        var account=$("#account").val();
        var password=$("#password").val();
        var identity=$("#identity").val();
        var yanzheng=$("#yanzheng").val();

        var weixin_key="";
        var weixin_key=$("#weixin_key").val();
        var reset="";
        var reset=$("#reset").val();
        if(account==""){
          $("#error_account").show();
          return 0;
        }else{
          $("#error_account").hide();
        }
        if(identity==""){
          $("#error_identity").show();
          return 0;
        }else{
          $("#error_identity").hide();
        }
        if(password==""){
          $("#error_password").show();
          return 0;
        }else{
          $("#error_password").hide();
        }
        if(yanzheng==""){
          $("#error_yanzheng").show();
          return 0;
        }else{
          $("#error_yanzheng").hide();
        }
        if(account!=""&&password!=""&&identity!=""&&yanzheng!=""){
          $("#error_account").hide();
          $("#error_password").hide();
          $("#error_identity").hide();
          $("#error_yanzheng").hide();
        }


      }
    });
    $("#button").on("click",function(){

      var account=$("#account").val();
      var identity=$("#identity").val();
      var password=$("#password").val();
      var yanzheng=$("#yanzheng").val();

      var weixin_key="";
      var weixin_key=$("#weixin_key").val();
      var reset="";
      var reset=$("#reset").val();
      if(account==""){

        $("#error_account").show();
        return 0;

      }else{ $("#error_account").hide();}
      if(identity==""){
        $("#error_identity").show();
        return 0;
      }else{
        $("#error_identity").hide();
      }
      if(password==""){

        $("#error_password").show();
        return 0;
      }
      else{ $("#error_password").hide();}
      if(yanzheng==""){
        $("#error_yanzheng").show();
        return 0;
      }else{
        $("#error_yanzheng").hide();
      }
      if(account!="" && password!=""&&identity!=""&&yanzheng!=""){

        //若均填写隐藏提示信息

        $("#error_account").hide();
        $("#error_identity").hide();
        $("#error_password").hide();
        $("#error_yanzheng").hide();

      }
    });
  });
</script>
</body>
</html>